﻿using System;

namespace Mr.WangFirstNugetPackage
{
    public class NugetTimeFirst
    {

        private static DateTime timeZero = new DateTime(1970, 01, 01).ToLocalTime();
        /// <summary>
        /// 格式化时间成字符串
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public string FormaterDateTimeToString(DateTime dateTime)
        {
            return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 把时间转化成Unix数值
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public uint ForamterDateTime2Unix(DateTime time)
        {
            return (uint)(time - timeZero).TotalSeconds;
        }

        /// <summary>
        ///转化成Unix时间转化成datatime
        /// </summary>
        /// <param name="timeSecondsNu"></param>
        /// <returns></returns>
        public DateTime FormaterUnix2DateTime(uint timeSecondsNu)
        {
            return timeZero.AddSeconds(timeSecondsNu);
        }
    }
}
